<template>
	<view>
		<u-sticky bgColor="#fff">
			<u-tabs :list="list" lineWidth="80" lineColor="#0F53AC" :activeStyle="activeStyle" :scrollable="false"
				:inactiveStyle="inactiveStyle" :itemStyle="itemStyle" @click="tabsClick" :current="current">
			</u-tabs>
		</u-sticky>
		<view class="tab-page" v-show="current==0">
			<view class="list-wrapper" v-for="(item,index) in repairList" :key="index">
				<view class="list-info">
					<view class="list-title">
						<view class="title-left">
							工单号:{{item.repairOrderNum}}
							<view class="copy" @click="copyOrderNum(item.repairOrderNum)">复制</view>
						</view>
						<view class="title-right"
							:class="[item.repairStatus==1||item.repairStatus==3?'title-dyz':item.repairStatus==2||item.repairStatus==5?'title-ongoing':item.repairStatus==9||item.repairStatus==4?'title-close':'']">
							{{item.repairStatus==1?'待维修':item.repairStatus==2?'维修中':item.repairStatus==3?'待验证':item.repairStatus==5?'维修完成':item.repairStatus==9?'维修关闭':'关闭-待验证'}}
						</view>
					</view>
				</view>
				<view class="list-main">
					<view class="item-main">
						<view class="main-left">
							<view class="txt1">设备名称</view>
							<view class="txt2">{{item.deviceName?item.deviceName:'--'}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">编号</view>
							<view class="txt2">{{item.deviceNum?item.deviceNum:'--'}}</view>
						</view>
					</view>
					<view class="item-main">
						<view class="main-left">
							<view class="txt1">{{'维修来源'}}</view>
							<view class="txt2">{{item.source==1?'正常报修':item.source==2?'维保报修':'点检报修'}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">故障等级</view>
							<view class="txt2">{{item.failureLevel?item.failureLevel:'--'}}</view>
						</view>
					</view>
					<view class="gz-desc">
						<view class="title">故障描述</view>
						<view class="desc-reason">{{item.description?item.description:'--'}}</view>
					</view>
					<view class="padding4"><u-gap height="1" bgColor="#f2f2f2"></u-gap></view>
					<view class="item-main">
						<view class="main-left">
							<view class="txt1">维修人</view>
							<view class="txt2">{{item.repairUserName?item.repairUserName:'--'}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">验证人</view>
							<view class="txt2">{{item.verifyUserName?item.verifyUserName:'--'}}</view>
						</view>
					</view>
					<view class="item-main">
						<view class="main-left">
							<view class="txt1">报修人</view>
							<view class="txt2">{{item.createUserName?item.createUserName:'--'}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">报修时间</view>
							<view class="txt2">{{item.createTime?item.createTime:'--'}}</view>
						</view>
					</view>
					<view class="gz-desc" v-if="item.verifyReason">
						<view class="title">
							<image class="img" src="@/static/images/index/warning.png" mode=""></image>验证不通过
						</view>
						<view class="desc-reason">{{item.verifyReason}}</view>
					</view>
					<!-- <view v-if="item.verifyReason" class="txt4">
						<view class="iconfont icon-app-gantanhao" style="margin-right: 10rpx;"></view>
						验证不通过：{{item.verifyReason}}
					</view> -->
				</view>
				<view class="item-btn">
					<view class="ruku" @click="toSelectDetail(item)">查看详情</view>
					<!-- <view v-if="item.closeRepairShowFlag==1&&item.repairStatus==1" class="chuku"
						@click="closeRepair(item)">关闭维修55555</view> -->
					<!-- <view class="su-line"></view> -->
					<view v-if="item.repairStatus==2&&userId==item.repairUserId" class="ruku"
						@click="togoRepairpage(item,1)">继续维修</view>
				</view>

			</view>
			<!-- <u-loadmore v-if="total>5" :status="status" :line="true" /> -->
			<view class="empty-data" v-if="repairList.length==0">
				<u-empty mode="data" :marginTop="100"></u-empty>
			</view>
		</view>
		<view class="tab-page" v-show="current==1">
			<view class="list-wrapper" v-for="(item,index) in repairList2" :key="index">
				<view class="list-info">
					<view class="list-title">
						<view class="title-left">
							工单号:{{item.repairOrderNum}}
							<view class="copy" @click="copyOrderNum(item.repairOrderNum)">复制</view>
						</view>
						<view class="title-right"
							:class="[item.repairStatus==1||item.repairStatus==3?'title-dyz':item.repairStatus==2||item.repairStatus==5?'title-ongoing':item.repairStatus==9||item.repairStatus==4?'title-close':'']">
							{{item.repairStatus==1?'待维修':item.repairStatus==2?'维修中':item.repairStatus==3?'待验证':item.repairStatus==5?'维修完成':item.repairStatus==9?'维修关闭':'关闭-待验证'}}
						</view>
					</view>
				</view>
				<view class="list-main">
					<view class="item-main">
						<view class="main-left">
							<view class="txt1">设备名称</view>
							<view class="txt2">{{item.deviceName}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">编号</view>
							<view class="txt2">{{item.deviceNum}}</view>
						</view>
					</view>
					<view class="item-main">
						<view class="main-left">
							<view class="txt1">维修来源</view>
							<view class="txt2">{{item.source==1?'正常报修':item.source==2?'维保报修':'点检报修'}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">故障等级</view>
							<view class="txt2">{{item.failureLevel}}</view>
						</view>
					</view>
					<view class="gz-desc">
						<view class="title">故障描述</view>
						<view class="desc-reason">{{item.description}}</view>
					</view>
					<view class="padding4"><u-gap height="1" bgColor="#f2f2f2"></u-gap></view>
					<view class="item-main">
						<view class="main-left">
							<view class="txt1">维修人</view>
							<view class="txt2">{{item.repairUserName}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">验证人</view>
							<view class="txt2">{{item.verifyUserName}}</view>
						</view>
					</view>
					<view class="item-main">
						<view class="main-left">
							<view class="txt1">报修人</view>
							<view class="txt2">{{item.createUserName}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">报修时间</view>
							<view class="txt2">{{item.createTime}}</view>
						</view>
					</view>
				</view>
				<view class="item-btn">

					<view  class="ruku" @click="toSelectDetail2(item)">查看详情</view>
					<view v-if="item.closeRepairShowFlag==1&&userId==item.repairUserId" class="chuku"
						@click="closeRepair(item)">关闭维修</view>
					<view v-if="item.closeRepairShowFlag==1&&item.repairEnterShowFlag==1&&item.repairStatus==2"
						class="su-line"></view>
					<view v-if="item.repairEnterShowFlag==1&&userId==item.repairUserId" class="ruku"
						@click="togoRepairpage2(item)">继续维修</view>

				</view>

			</view>
			<!-- <u-loadmore v-if="total2>5" :status="status2" :line="true" /> -->
			<view class="empty-data" v-if="repairList2.length==0">
				<u-empty mode="data" :marginTop="100"></u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 'loadmore',
				status2: 'loadmore',
				activeStyle: {
					color: '#0F53AC',
					fontWeight: 'bold',
					transform: 'scale(1.05)'
				},
				inactiveStyle: {
					color: '#8c8c8c',
					transform: 'scale(1)'
				},
				itemStyle: {
					paddingLeft: '30rpx',
					paddingRight: '30rpx',
					paddingTop: '24rpx',
					paddingBottom: '24rpx',
					height: '48rpx'
				},
				current: 0,
				list: [{
					name: '内部维修',
				}, {
					name: '委外维修',
				}],
				option: [{
						text: '全部',
						value: ''
					}, {
						text: '正常报修',
						value: 1
					},
					{
						text: '维保报修',
						value: 2
					},
					{
						text: '点检报修',
						value: 3
					}
				],
				value1: '',
				value3: '',
				option2: [{
						text: '全部',
						value: ''
					}, {
						text: '待维修',
						value: 1
					},
					{
						text: '维修中',
						value: 2
					},
					{
						text: '待验证',
						value: 3
					},
					{
						text: '关闭-待验证',
						value: 4
					}
				],
				value2: '',
				option3: [{
						text: '全部',
						value: ""
					}, {
						text: '维修完成',
						value: 5
					},
					{
						text: '维修关闭',
						value: 9
					}
				],
				value4: "",
				params: {
					pn: 1,
					ps: 5,
					type: 1, //必须 1、获取待维修工单   2.获取已维修工单
					repairStatus: '', //维修状态；1.待维修； 2.维修中； 3.待验证 4.关闭-待验证；5.维修完成 ；9.维修关闭
					source: '', // 报修来源；1.正常报修；2.维保报修；3.点检报修；
				},
				repairList: [],
				repairList2: [],
				pages: 1,
				total: 0,
				pages2: 1,
				total2: 0,
				userId: ""
			}
		},
		onLoad(options) {
			this.userId = uni.getStorageSync('userInfo').userId;
			this.getList();
		},

		methods: {
			leftClick() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},

			toSelectDetail2(item) {
				uni.navigateTo({
					url: '/pages/subPackagesB/weiwaiRepair/repairDetail?orderNum=' + item.repairOrderNum
				})
			},

			//去往委外页面
			gotoOutsourcing(item) {
				console.log('item', item)
				uni.navigateTo({
					url: '/pages/subPackagesB/weiwaiRepair/repairlist?deviceId=' + item.deviceId + '&orderNum=' +
						item.repairOrderNum + '&repairId=' + item.id
				})
			},
			tabsClick(e) {
				this.current = e.index
			},
			toggleItem(val) {
				if (val === 1) {
					this.$refs.dropdown1.close()
				}
			},

			closeRepair(item) {
				uni.navigateTo({
					url: '/pages/subPackagesA/repairList/closerepair?repairId=' + item.id
				})
			},
			togoRepairpage(item, type) {
				// type 2-开始维修 1-继续维修
				if (type == 2) {
					uni.$u.http.put(`/device/mobile/deviceRepair/beginRepair/${item.id}`).then(res => {
						console.log('res===>', res)
						if (res.code == 0) {}
					}).catch(err => {})

				}
				uni.navigateTo({
					url: '/pages/subPackagesA/repairList/repairinfo?deviceId=' + item.deviceId + '&orderNum=' +
						item.repairOrderNum + '&repairId=' + item.id + '&deviceType=' + item.deviceType
				})
			},
			togoRepairpage2(item) {
				if (item == 1) {
					uni.navigateTo({
						url: '/pages/subPackagesB/weiwaiRepair/repairlist?orderNum=' + ''
					})
				} else {
					uni.navigateTo({
						url: '/pages/subPackagesB/weiwaiRepair/repairlist?orderNum=' + item.repairOrderNum
					})

				}
			},
			toSelectDetail(item) {
				uni.navigateTo({
					url: '/pages/subPackagesA/repairList/wxDetail?orderNum=' + item.repairOrderNum + '&repairId=' +
						item.id
				})
			},
			getList() {
				uni.$u.http.get(`/device/mobile/deviceRepair/selectNotRepairList`).then(res => {

					if (res.code == 0) {
						this.repairList = res.data.filter(item => item.repairType == 1)
						this.repairList2 = res.data.filter(item => item.repairType == 2)
						// this.repairList = this.repairList.concat(res.data)
						// this.pages = res.data.pages;
						// this.total = res.data.total;
					}
				}).catch(err => {})
			},
			// getList2() {
			// 	uni.$u.http.post(`/device/mobile/deviceRepair/outsourceRepairList`, this.params).then(res => {
			// 		console.log('res===>list', res)
			// 		if (res.code == 0) {
			// 			this.repairList2 = this.repairList2.concat(res.data.records)
			// 			this.pages2 = res.data.pages;
			// 			this.total2 = res.data.total;
			// 		}
			// 	}).catch(err => {})
			// },
			copyOrderNum(data) {
				uni.setClipboardData({
					data: data,
					success: function() {
						console.log('success');
						uni.$u.toast('复制成功')
					}
				});
			}
		},
		onReachBottom() {
			if (this.current == 0) {
				if (this.params.pn >= this.pages) return;
				this.status = 'loading';
				this.params.pn = ++this.params.pn;
				setTimeout(() => {
					this.getList()
					if (this.params.pn >= this.pages) this.status = 'nomore';
					else this.status = 'loading';
				}, 1000)
			}
			if (this.current == 1) {
				if (this.params.pn >= this.pages2) return;
				this.status2 = 'loading';
				this.params.pn = ++this.params.pn;
				setTimeout(() => {
					this.getList()
					if (this.params.pn >= this.pages2) this.status2 = 'nomore';
					else this.status2 = 'loading';
				}, 1000)
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #ffffff;
	}

	.tab-page {
		margin-top: 2rpx;
	}

	.dropdown {
		.list2 {
			.sort {
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 26rpx;
				color: #000000;
				padding: 20rpx 0;
			}
		}

		.sort-list {
			width: 100%;
			height: 100vh;
			background: #9d9d9d;
			z-index: 22;
			position: absolute;

			.sort-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 10rpx 40rpx 10rpx 20rpx;
				font-size: 34rpx;
				border-bottom: 1px solid #f2f2f2;
				z-index: 99;
				position: relative;
				background: #fff;
			}

			.sort-item:last-child {
				border-bottom: none;
			}

			.sort-item:first-child {
				border-top: 1px solid #f2f2f2;
			}
		}
	}

	.list-wrapper {
		.list-info {
			margin-top: 10rpx;
			background: #fff;
			padding: 20rpx 40rpx;

			.list-title {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.title-left {
					display: flex;
					align-items: center;
					font-size: 30rpx;
					color: #000000;

					.copy {
						color: #8c8c8c;
						font-size: 20rpx;
						margin-left: 10rpx;
						border-radius: 8rpx;
						background: #f2f2f2;
						padding: 5rpx 10rpx;
					}
				}

				.title-right {
					height: 48rpx;
					line-height: 48rpx;
					text-align: center;
					border-radius: 8rpx;
					font-size: 24rpx;
					padding: 0 20rpx;
				}

				.title-ongoing {
					color: #0F53AC;
					background-color: rgba(2, 173, 130, 0.3);
				}

				.title-dyz {
					color: #1962e0;
					background-color: rgba(27, 114, 252, 0.3);
				}

				.title-close {
					color: #fc770a;
					background-color: rgba(255, 120, 10, 0.3);
				}

				.title-finish {
					color: #00bf56;
					background-color: rgba(0, 238, 107, 0.3);
				}
			}

		}

		.list-main {
			padding: 4rpx 10rpx 20rpx 10rpx;
			background: #fff;
			border-top: 1px solid #f2f2f2;
			border-bottom: 1px solid #f2f2f2;

			.item-main {
				display: flex;
				justify-content: space-between;
				padding: 4rpx 30rpx;

				.main-left {
					width: 50%;
					text-align: left;

					.txt1 {
						color: #8c8c8c;
						font-size: 28rpx;
						padding: 10rpx 0;
					}

					.txt2 {
						color: #2b2b2b;
						font-size: 28rpx;
					}
				}
			}

			.txt4 {
				color: #fa4016;
				font-size: 28rpx;
				display: flex;
				align-items: center;
				padding-left: 30rpx;
			}

			.gz-desc {
				padding: 15rpx 30rpx;

				.title {
					font-size: 30rpx;
					color: #8c8c8c;
				}

				.desc-reason {
					font-size: 32rpx;
					color: #2b2b2b;
					margin-top: 15rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}
			}
		}

		.item-btn {
			display: flex;
			justify-content: space-around;
			align-items: center;
			padding: 20rpx 0;
			background: #fff;

			.chuku {
				width: 45%;
				font-size: 34rpx;
				color: #8c8c8c;
				text-align: center;
			}

			.ruku {
				width: 45%;
				font-size: 34rpx;
				color: #0F53AC;
				text-align: center;
			}

			.su-line {
				width: 4rpx;
				height: 50rpx;
				background: #f2f2f2;
			}
		}
	}

	.fixed-btn {
		position: fixed;
		bottom: 200rpx;
		right: 20rpx;
		z-index: 99;
		width: 160rpx;
		height: 160rpx;
		opacity: 1;
		background: rgba(2, 173, 130, 0.8);
		box-shadow: 6px 5px 20px 0px rgba(2, 173, 130, 0.4);
		border-radius: 50%;
		font-size: 28rpx;
		display: flex;
		align-items: center;
		flex-direction: column;
		color: #fff;

		.btn-icon {
			margin-top: 15rpx;

			image {
				width: 72rpx;
				height: 72rpx;
			}
		}
	}

	.gz-desc {
		padding: 15rpx 30rpx;

		.title {
			font-size: 28rpx;
			color: #8c8c8c;
			display: flex;
			align-items: center;

			.img {
				width: 16px;
				height: 16px;
			}
		}

		.desc-reason {
			font-size: 28rpx;
			color: #2b2b2b;
			margin-top: 15rpx;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 2;
			-webkit-box-orient: vertical;
		}
	}
</style>